-
Notifications
You must be signed in to change notification settings - Fork 763
Upgrade Elasticsearch from 7.x to 8.18.0 #6640
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
kitsune/search/base.py
Outdated
) | ||
|
||
# Handle special case where an index with same name as alias exists | ||
try: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a reason for adding this check?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I can drop this; I added this when troubleshooting test issues with index and alias collisions. I'll see if dropping it causes problems to recur.
kitsune/search/es_utils.py
Outdated
"request_timeout": settings.ES_TIMEOUT, | ||
"retry_on_timeout": settings.ES_RETRY_ON_TIMEOUT, | ||
# SSL settings - these are needed for ES8 which requires SSL by default | ||
"verify_certs": settings.ES_VERIFY_CERTS, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what's the reason for introducing all these new settings?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ES8 requires the SSL settings. retry_on_timeout
was an attempt to improve reliability when troubleshooting test issues; the same with the sniff_on_start
and sniff_on_connection_fail
.
We can drop the sniff_*
settings, but should consider leaving the retry_on_timeout
. May not be critical but it could help when/if there are real connection issues.
kitsune/search/es_utils.py
Outdated
"sniff_on_connection_fail": settings.ES_SNIFF_ON_CONNECTION_FAIL, | ||
} | ||
|
||
if settings.ES_HTTP_AUTH: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this needed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Authentication isn't always needed, and since it seems conditional it's pulled out on its own. That separates auth stuff from the more consistent/base connection settings, which we will always have.
I think it's a good pattern but am open to feedback.
That said, I don't think we have a case where we don't use auth.
@@ -134,10 +159,15 @@ def index_object(doc_type_name, obj_id): | |||
# just return | |||
return | |||
|
|||
kwargs = {} | |||
# For ES8, use string "true" instead of boolean True for refresh parameter | |||
if settings.TEST: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You already have this check above
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are three checks for settings.TEST
in the file. The es_client
has one to modify timeout and retry as part of local testing, index_object()
and delete_object()
both test to set the refresh to true. It didn't seem reasonable to pull that check into a helper function just for the second two tests. I don't think we want refresh
set to true generally, as it forces an immediate refresh which would be expensive in prod.
I think we could remove the code I added for troubleshooting/resolving tests (so the es_client() timeout, retries and retry_on_timeout) and that would get rid of the test in es_client()
. But we want the test in the other two places for sure.
kitsune/search/es_utils.py
Outdated
kwargs = {} | ||
# For ES8, use string "true" instead of boolean True for refresh parameter | ||
if settings.TEST: | ||
kwargs["refresh"] = "true" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the purpose of this argument?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It forces ES to refresh, making changes immediately visible to search. So it helps for local testing more than anything else.
@@ -7,6 +7,7 @@ | |||
|
|||
class ForumDocumentSignalsTests(Elastic7TestCase): | |||
def setUp(self): | |||
super().setUp() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure that we need this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since I changed the ElasticTestCase
it is needed. Now we set the test environment up cleanly, force a refresh, and get in front of any index issues.
@@ -46,9 +48,16 @@ def make_first_doc_throw_exception(self, *args, **kwargs): | |||
question = Question.objects.get(id=question_id) | |||
AnswerFactory(question=question, content=f"answer {question_id}") | |||
|
|||
# Force ES index refresh before testing | |||
QuestionDocument._index.refresh() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are you introducing this change? Did something change between 7 and 8?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just more ensuring that tests don't fail because of a delay between adding something to the index and it appearing in search results. So, tests won't fail due to timing issues.
8fcee02
to
bef0b8a
Compare
7 and 8. We import both python libraries `elasticsearch7` and `elasticsearch8` We test the server version and set it in `settings.py` We use the correct library based on the server major version Server vwrsion check is now in `search/utils.py` and uses module level caching to prevent unneeded connections
This commit upgrades our Elasticsearch infrastructure from version 7.x to 8.18.0,
including:
elasticsearch7
andelasticsearch8
elasticsearch-dsl
dependency in favor ofelasticsearch.dsl
when on ES8elasticsearch_dsl
toelasticsearch.dsl
test_es7_utils.py
totest_es_utils.py
with updated test casessettings.py
This upgrade provides better security, performance improvements, and access to newer
Elasticsearch features while maintaining backward compatibility with our existing
search functionality.
NOTE: We will need to plan and execute an upgrade path with hosted Elastic; this PR only solves code compatibility caused by breaking changes.